//
//  WLGP_BottonView.m
//  录音转文字助手
//
//  Created by 王亮 on 2020/9/9.
//  Copyright © 2020 录音转文字助手. All rights reserved.
//

#import "WLGP_BottonView.h"
#import "DLStore.h"
#import "WLGP_AgreementWebViewViewController.h"

@interface WLGP_BottonView ()

@property (strong, nonatomic)  UIButton *tiaokuan_button;
@property (strong, nonatomic)  UIButton *yinsi_monte;
@property (strong, nonatomic)  UIButton *huifu_monte;

@end
@implementation WLGP_BottonView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = UIColor.redColor;
        [self addSubview:self.tiaokuan_button];
        [self addSubview:self.yinsi_monte];
        [self addSubview:self.huifu_monte];
        [self.tiaokuan_button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self);
            make.right.mas_equalTo(self.yinsi_monte.mas_left).mas_offset(-10);
        }];
        [self.yinsi_monte mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.mas_equalTo(self);
        }];
        [self.huifu_monte mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.mas_equalTo(self);
            make.left.mas_equalTo(self.yinsi_monte.mas_right).mas_offset(10);
        }];
    }
    return self;
}
-(UIButton *)tiaokuan_button{
    if (!_tiaokuan_button) {
        _tiaokuan_button = [[UIButton alloc]init];
        [_tiaokuan_button setTitle:@"【使用条款】" forState:UIControlStateNormal];
        _tiaokuan_button.titleLabel.font = [UIFont systemFontOfSize:11];
        [_tiaokuan_button setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        [_tiaokuan_button addTarget:self action:@selector(click_shiyongtiaokuan:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _tiaokuan_button;
}
-(UIButton *)yinsi_monte{
    if (!_yinsi_monte) {
        _yinsi_monte = [[UIButton alloc]init];
        [_yinsi_monte setTitle:@"【隐私政策】" forState:UIControlStateNormal];
        [_yinsi_monte setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        _yinsi_monte.titleLabel.font = [UIFont systemFontOfSize:11];
        [_yinsi_monte addTarget:self action:@selector(click_yinsizhengce:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _yinsi_monte;
}

-(UIButton *)huifu_monte{
    if (!_huifu_monte) {
        _huifu_monte = [[UIButton alloc]init];
        [_huifu_monte setTitle:@"【恢复购买】" forState:UIControlStateNormal];
        [_huifu_monte setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        _huifu_monte.titleLabel.font = [UIFont systemFontOfSize:11];
        [_huifu_monte addTarget:self action:@selector(click_huifugoumai:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _huifu_monte;
}


//使用条款
- (void)click_shiyongtiaokuan:(id)sender {
    WLGP_AgreementWebViewViewController *vc = [[WLGP_AgreementWebViewViewController alloc]init];
    vc.htmlName = @"UserProtocol";
    vc.title = @"使用条款";
    [[self wl_viewController].navigationController pushViewController:vc animated:YES];
}
//隐私政策
- (void)click_yinsizhengce:(id)sender {
    WLGP_AgreementWebViewViewController *vc = [[WLGP_AgreementWebViewViewController alloc]init];
    vc.htmlName = @"PrivacyClauses";
    vc.title = @"隐私条款";
    [[self wl_viewController].navigationController pushViewController:vc animated:YES];
}
//恢复购买
- (void)click_huifugoumai:(id)sender {
    [SVProgressHUD showMask_wl];
    [[DLStore singletonMod] dl_restoreTransactionsOnSuccess:^(NSArray * _Nonnull transactions) {
        if (transactions.count){
            [SVProgressHUD showSuccess_wl:@"操作成功"];
        } else {
            [SVProgressHUD showSuccess_wl:@"没有查询到购买记录"];
        }
    } failure:^(NSError * _Nonnull error) {
        [SVProgressHUD showSuccess_wl:@"没有查询到购买记录"];
    }];
}
@end
